<template>
    <!-- 修改资料 -->
    <div>
        <!-- 内容主题区域 -->
        <el-form label-width="75px" :model="form" label-position="right" ref="formRef" :rules="formRules">
            <el-row>
                <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
                    <el-form-item label="编号" prop="number">
                        <el-input style="width:70%" v-model="form.number" placeholder="请输入编号"></el-input>&nbsp;
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
                    <el-form-item label="名称" prop="name">
                        <el-input v-model="form.name" placeholder="请输入名称"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
                    <el-form-item label="功能模块" prop="metaModuleId">
                        <ts-select v-model="form.metaModuleId" fileName="MetaModuleReport" :template="tableProps"
                            @updateRow="metaModuleChange" :label="form.metaModuleName"></ts-select>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
                    <el-form-item label="上传附件" prop="file">
                        <div style="display: flex;">
                        <tsUpload type="file" :image-url="imageUrl" @updateFile="updateFile"></tsUpload>
                        <el-button @click="downFile">下 载</el-button>
                    </div>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
                    <el-form-item label="状态" prop="status">
                        <el-switch v-model="form.status" active-value="normal" inactive-value="disable"></el-switch>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
                    
            <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" type="textarea"></el-input>
            </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <div class="button-position">
            <el-button @click="updateVisible">取 消</el-button>
            <el-button type="primary" @click="update(formRef)">确 定</el-button>
        </div>
    </div>
</template>

<script setup>
import { reactive, ref, onMounted } from 'vue';
import { ElNotification } from 'element-plus';
import { Check, Close } from '@element-plus/icons-vue';
import Api from '@/api/model/meta'
import sysApi from '@/api/model/system';
import tsSelect from '@/components/scSelect/index.vue'
import tsUpload from '@/components/tsUpload/file.vue'
const emit = defineEmits(['updatetable'])
const props = defineProps({
    paramsData: {
        type: Object,
        defalut: {}
    }
})
// 添加用户数据的对象
const form = ref({});
const configData = ref({})
const imageUrl = reactive({
    name: '',
    url: ''
})
const formRef = ref()
const tableProps = {
    value: 'id',
    label: 'name'
}
onMounted(() => {
    getInit()
})

const getInit = async () => {
    let formRes = await Api.reportDesigner.detail.post(props.paramsData)
    if (formRes.code == 200) {
        form.value = formRes.data
        imageUrl.url = formRes.data.fileFullPath
        imageUrl.name = formRes.data.fileName
        configData.value = formRes.configData
    }
}


const restAddFormData = () => {
    formRef.value.resetFields();
}

const updateVisible = (val) => {
    emit('updatetable')
}
const updateFile = (val) => {
    form.value.file = val
}
// 上传
const update = async (formRef) => {
    await formRef.validate((valid, fields) => {
        if (valid) {
            updateData();
        }
    })
}

const updateData = async () => {
    let params = {
        bean: form.value,
    }
    let res = await Api.reportDesigner.update.post(params);
    if (res.code == 200) {
        restAddFormData()
        ElNotification.success({ title: '', message: '添加成功！', duration: 2000 });
        emit('updatetable', true)
    }
}
const downFile = async()=>{
    let params = {
        saveAsFileName: form.value.fileName,
        downloadFileName: form.value.excelTemplateFile
    }
    let res = await sysApi.uploadfile.post(params)
}
</script>

<style lang="less" scoped></style>
